package middleware

import (
	"github.com/gin-gonic/gin"
	"nodeseller/encrypt"
	"nodeseller/response"
)

func CheckUserInfo(c *gin.Context) {
	defer c.Abort()
	phone ,err := c.Cookie("phone")
	if err != nil{
		response.Response1(c,1,"身份验证失败，请重新登陆1","")
		return
	}
	sign,err := c.Cookie("sign")
	if err != nil{
		response.Response1(c,1,"身份验证失败，请重新登陆2","")
		return
	}
	//对信息进行解密
	signByte,err := encrypt.DePwsCode(sign)
	if err != nil{
		response.Response1(c,1,"身份验证失败，请重新登陆3","")
		return
	}
	if checkInfo(phone,string(signByte)){
		c.Next()
	}else {
		response.Response1(c,1,"身份验证失败，请重新登陆4","")
		return
	}
}
//自定义逻辑判断
func checkInfo(checkStr string,signStr string)bool  {
	if checkStr == signStr{
		return true
	}
	return false
}
